﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using GTS.Channel.Api.Entity;
using Pub.Class;

namespace GTS.Channel.Api.Helper {
    /// <summary>
    /// 操作类
    /// 
    /// 修改纪录
    ///     2012-04-12 版本：1.0 系统自动创建此类
    /// 
    /// </summary>
    public partial class ChannelInfoHelper {
        /// <summary>
        /// 缓存多少秒 x 5
        /// </summary>
        public static int cacheSeconds = 1440;
        /// <summary>
        /// 查询所有记录
        /// </summary>
        /// <param name="where">附加条件，统一的前面要加链接符（and、or等等）</param>
        /// <param name="order">排序字段，不加“order by”</param>
        /// <param name="fieldList">设置需要返回的字段</param>
        /// <param name="dbkey">存在数据库连接池中的连接key，为空时随机取连接key</param>
        /// <returns>返回实体记录集</returns>
        public static IList<ChannelInfo> SelectListByAll(string where = "", string order = "", string fieldList = "", string dbkey = "") {
            string cacheNameKey = "ChannelInfoCache_SelectListByAll_{0}_{1}_{2}".FormatWith(where, order, fieldList);
            return Cache2.Get<IList<ChannelInfo>>(cacheNameKey, cacheSeconds, () => {
                string strSql = string.Empty;
                if (fieldList.IsNullEmpty()) {
                    strSql = new SQL().From(ChannelInfo._)
                        .Select(ChannelInfo._ChannelID)
                        .Select(ChannelInfo._ChannelName)
                        .Select(ChannelInfo._SPCode)
                        .Select(ChannelInfo._CstCode)
                        .Select(ChannelInfo._LongPhone)
                        .Select(ChannelInfo._Instruction)
                        .Select(ChannelInfo._Price)
                        .ToString();
                } else {
                    strSql = new SQL().From(ChannelInfo._).Select(fieldList).ToString();
                }
                if (!where.IsNullEmpty()) strSql += " where 1=1 " + where;
                if (!order.IsNullEmpty()) strSql += " order by " + order;
                return Data.Pool(dbkey).GetDbDataReader(strSql).ToList<ChannelInfo>();
            });
        }
        /// <summary>
        /// 查询所有记录
        /// </summary>
        /// <param name="dbkey">存在数据库连接池中的连接key，为空时随机取连接key</param>
        /// <returns>返回实体记录集</returns>
        public static IList<ChannelInfo> SelectListByAll(string dbkey = "") {
            return SelectListByAll("", "", "", dbkey);
        }
        /// <summary>
        /// 清除查询所有记录的缓存
        /// </summary>
        public static void ClearCacheSelectListByAll() {
            //Cache2.Remove("ChannelInfoCache_SelectListByAll___");
            Cache2.RemoveByPattern("ChannelInfoCache_SelectListByAll_(.+?)");
        }
    }
    /// <summary>
    /// 操作类
    /// 
    /// 修改纪录
    ///     2012-04-12 版本：1.0 系统自动创建此类
    /// 
    /// </summary>
    public partial class IVRChannelInfoHelper {
        /// <summary>
        /// 缓存多少秒 x 5
        /// </summary>
        public static int cacheSeconds = 1440;
        /// <summary>
        /// 查询所有记录
        /// </summary>
        /// <param name="where">附加条件，统一的前面要加链接符（and、or等等）</param>
        /// <param name="order">排序字段，不加“order by”</param>
        /// <param name="fieldList">设置需要返回的字段</param>
        /// <param name="dbkey">存在数据库连接池中的连接key，为空时随机取连接key</param>
        /// <returns>返回实体记录集</returns>
        public static IList<IVRChannelInfo> SelectListByAll(string where = "", string order = "", string fieldList = "", string dbkey = "") {
            string cacheNameKey = "IVRChannelInfoCache_SelectListByAll_{0}_{1}_{2}".FormatWith(where, order, fieldList);
            return Cache2.Get<IList<IVRChannelInfo>>(cacheNameKey, cacheSeconds, () => {
                string strSql = string.Empty;
			    if (fieldList.IsNullEmpty()) {
                    strSql = new SQL().From(IVRChannelInfo._)
                        .Select(IVRChannelInfo._ChannelID)
                        .Select(IVRChannelInfo._ChannelName)
                        .Select(IVRChannelInfo._CstCode)
                        .Select(IVRChannelInfo._LongPhone)
                        .Select(IVRChannelInfo._SPCode)
                        .Select(IVRChannelInfo._Price)
                        .ToString();
                } else {
			        strSql = new SQL().From(IVRChannelInfo._).Select(fieldList).ToString();
                }
                if (!where.IsNullEmpty()) strSql += " where 1=1 " + where;
                if (!order.IsNullEmpty()) strSql += " order by " + order;
                return Data.Pool(dbkey).GetDbDataReader(strSql).ToList<IVRChannelInfo>();
            });
        }
        /// <summary>
        /// 查询所有记录
        /// </summary>
        /// <param name="dbkey">存在数据库连接池中的连接key，为空时随机取连接key</param>
        /// <returns>返回实体记录集</returns>
        public static IList<IVRChannelInfo> SelectListByAll(string dbkey = "") {
            return SelectListByAll("", "", "", dbkey);
        }
        /// <summary>
        /// 清除查询所有记录的缓存
        /// </summary>
        public static void ClearCacheSelectListByAll() {
            //Cache2.Remove("IVRChannelInfoCache_SelectListByAll___");
            Cache2.RemoveByPattern("IVRChannelInfoCache_SelectListByAll_(.+?)");
        }
    }

    public partial class ChannelDealDataHelper {
        public static string GetPLMN(string dbkey, string linkID, string sPCode) {
            DbParameter[] dbparam = new DbParameter[]{
                Data.MakeInParam("@LinkID", (DbType)SqlDbType.VarChar,100, linkID),
                Data.MakeInParam("@SPCode", (DbType)SqlDbType.VarChar,20, sPCode)
            };
            object objValue = Data.Pool(dbkey).GetScalar("[ChannelDealData_SelectByInfo]", dbparam);
            if (objValue.IsNull()) return "";
            return objValue.ToString();
        }
    }
}

